#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int
main(void)
{
	char buffer[1024];
	
	int n = 0;
	n = read(STDIN_FILENO, buffer, sizeof(buffer));

	if(n < 0){
		perror("read faild");
		exit(0);
	}

	char path1[] = "test1.txt";
	char path2[] = "test2.txt";

	int fd  = open(path1, O_RDWR | O_CREAT | O_TRUNC, 0755);
	if(fd < 0) perror("open test1.txt faild");

	if(unlink(path1) < 0) perror("unlink failed");

	write(fd, buffer, n);

	link(path1, path2);
	
	char p[] = "g";
	
	close(fd);

	exit(0);

}
